<?
include("../lib/config.php");
$nik 	= $HTTP_GET_VARS['nik'];
$op		= $HTTP_GET_VARS['op'];
$no		= $HTTP_GET_VARS['no'];

if($op == "edit"){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("WITH limit AS(SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM VPenugasan WHERE NIK='$nik') SELECT * FROM limit WHERE No='$no' ",$conn);
	$row	= mssql_fetch_array($query);
}
else{
	$Faction = "../lib/save.php";
	$Vbutton = "Simpan";
}

include("../header.php");
?>
<script type="text/javascript">
	function LoadFocus(){
		document.forms[0].elements[0].focus();
	}
	
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};

	function Validate(){
		if(document.FEmployee.nik.value == "")
		{
			alert("Field : NIK tidak boleh kosong ...");
			document.FEmployee.nik.focus();
			return false;
		}

		if(document.FEmployee.no_surat.value == "")
		{
			alert("Field : No. Surat tidak boleh kosong ...");
			document.FEmployee.no_surat.focus();
			return false;
		}
		
		if(document.FEmployee.tgl_surat.value == "")
		{
			alert("Field : Tanggal Surat tidak boleh kosong ...");
			document.FEmployee.tgl_surat.focus();
			return false;
		}
		
		if(document.FEmployee.tgl_dari.value == "")
		{
			alert("Field : Dari Tanggal tidak boleh kosong ...");
			document.FEmployee.tgl_dari.focus();
			return false;
		}

		if(document.FEmployee.tgl_sampai.value == "")
		{
			alert("Field : Sampai Tanggal tidak boleh kosong ...");
			document.FEmployee.tgl_sampai.focus();
			return false;
		}


		if(document.FEmployee.tujuan.value == "")
		{
			alert("Field : Tujuan tidak boleh kosong ...");
			document.FEmployee.tujuan.focus();
			return false;
		}
		

		if(document.FEmployee.keperluan.value == "")
		{
			alert("Field : Keperluan tidak boleh kosong ...");
			document.FEmployee.keperluan.focus();
			return false;
		}

/*
		if(document.FEmployee.lokasi.value == "")
		{
			alert("Field : Lokasi tidak boleh kosong ...");
			document.FEmployee.lokasi.focus();
			return false;
		}

		if(document.FEmployee.bagian.value == "")
		{
			alert("Field : Bagian tidak boleh kosong ...");
			document.FEmployee.bagian.focus();
			return false;
		}

		if(document.FEmployee.detail_posisi.value == "")
		{
			alert("Field : Detail Posisi tidak boleh kosong ...");
			document.FEmployee.detail_posisi.focus();
			return false;
		}

		if(document.FEmployee.nama_jabatan.value == "")
		{
			alert("Field : Nama Jabatan tidak boleh kosong ...");
			document.FEmployee.nama_jabatan.focus();
			return false;
		}

		if(document.FEmployee.golongan.value == "")
		{
			alert("Field : Golongan harus dipilih ...");
			document.FEmployee.golongan.focus();
			return false;
		}

		if(document.FEmployee.status_karyawan.value == "")
		{
			alert("Field : Status Karyawan harus dipilih ...");
			document.FEmployee.status_karyawan.focus();
			return false;
		}
*/
		document.FEmployee.submit();
		
	}
	
	function show_popup(page)
	{
		child = open
		(
			"frm_list_emp.php",
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}
</script>
</head>

<body onLoad="Javascript:LoadFocus();">
   <table width="93%" class="table_indent2">
    <tr>
	 <td class="line_bottom">&nbsp;&nbsp;<b>Penugasan</b></td>
	</tr>
   </table>
<form name="FEmployee" method="post" action="<?=$Faction?>">
<table width="100%" border="0">
 <tr>
  <td colspan="2">
   <table width="100%" border="0">
    <tr>
	 <td width="100">NIK</td>
	 <td><input type="text" name="nik" readonly="" value="<?=$nik?>" />
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup()'><img src='../images/people.png' border=0></a>";
		}
	?>
	 </td>
	</tr>
	<tr>
	 <td>Nama</td>
	 <td><input type="text" name="nama" readonly="" value="<?
if(empty($row[Nama]))
{
 echo $HTTP_GET_VARS['nama'];
}
else{
 echo"$row[Nama]";
}

?>" /></td>
	</tr>
	<tr>
	 <td colspan="3"><hr noshade="noshade" size="-2" /></td>
	</tr>
   </table>
  </td>
 </tr>
 <tr>
 <td valign="top" colspan="2">
 <fieldset><legend>SURAT KEPUTUSAN</legend>
 <table border="0">
 <tr>
  <td width="150">No. Surat</td>
  <td>: <input type="text" maxlength="50" value="<?=$row[no_surat]?>" size="35" class="text" name="no_surat"/> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Tanggal Surat</td>
  <td>: <input type="text" maxlength="10" value="<?=$row[TglSurat]?>" size="10"  class="text" name="tgl_surat"/> <span class="required">*</span> <a href="javascript:calA.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a>
  </td>
 </tr>
 <tr>
  <td>Dari Tanggal</td>
  <td>: <input type="text" maxlength="10" value="<?=$row[TglDari]?>" size="10"  class="text" name="tgl_dari"/> <span class="required">*</span> <a href="javascript:calB.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a></td>
 </tr>
 <tr>
  <td>Sampai Tanggal</td>
  <td>: <input type="text" maxlength="10" value="<?=$row[TglSampai]?>" size="10"  class="text" name="tgl_sampai"/> <span class="required">*</span> <a href="javascript:calC.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a></td>
 </tr>
 <tr>
  <td valign="top" colspan="2">Tujuan: <span class="required">*</span></td>
 </tr>
 <tr>
  <td valign="top" colspan="2"><textarea name="tujuan" rows="6" cols="60"><?=$row[tujuan]?></textarea></td>
 </tr>
 <tr>
  <td valign="top" colspan="2">Keperluan: <span class="required">*</span></td>
 </tr>
 <tr>
  <td valign="top" colspan="2"><textarea name="keperluan" rows="6" cols="60"><?=$row[keperluan]?></textarea></td>
 </tr>
 </table>
 </fieldset>
 </td>
 <!--
 <td valign="top">
 <fieldset><legend>DATA KARYAWAN</legend>
 <table> 
 <tr>
  <td>Lokasi</td>
  <td>: 
  <select name="lokasi" style="width:250px;">
  	<?
	/*
		$sgetL = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi='$row[lokasi]'",$conn);
		$rgetL = mssql_fetch_array($sgetL);
	//	echo"<option value='$rgetL[kode_lokasi]'>$rgetL[propinsi] - $rgetL[distrik]</option>";
	?>
   <option value="">--Pilih--</option>
   <?
   		/*
		$slokasi	= mssql_query("SELECT * FROM MstLokasi ORDER BY propinsi, distrik",$conn);
		while($rlokasi = mssql_fetch_array($slokasi)){
			echo"<option value='$rlokasi[kode_lokasi]'>$rlokasi[propinsi] - $rlokasi[distrik]</option>";
		}
		*/
   ?>
  </select>
  <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Unit Kerja</td>
  <td>: 
  <select name="bagian" style="width:250px;">
  	<?
		/*
		$sgetB = mssql_query("SELECT * FROM MstSO WHERE kode_so='$row[kode_so]'",$conn);
		$rgetB = mssql_fetch_array($sgetB);
		echo"<option value='$rgetB[kode_so]'>$rgetB[kode_so] - $rgetB[uraian]</option>";
	?>
   <option value="">--pilih--</option>
   <?
   		$sqlbag = mssql_query("SELECT * FROM MstSO ORDER BY kode_so",$conn);
		while($rowbag = mssql_fetch_array($sqlbag)){
			echo"<option value='$rowbag[kode_so]'>$rowbag[kode_so] - $rowbag[uraian]</option>";
		}
		*/
   ?>
  </select>
  <span class="required">*</span></td>
 </tr>
 <tr>
  <td valign="top">Detail Posisi</td>
  <td valign="top">: 
  <textarea cols="30" rows="5" name="detail_posisi"><?=$row[DetailPosisi]?></textarea>
  <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Nama Jabatan</td>
  <td>: <input type="text" maxlength="25" value="<?=$row[nama_jab]?>" size="25"  class="text" name="nama_jabatan"/> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Golongan</td>
  <td>: 
  <select name="golongan">
   <option value="<?=$row[golongan]?>"><?=$row[golongan]?></option>
   <option value="">--Pilih--</option>
   <?
   /*
   	for($i=0;$i<=15;$i++){
		echo"<option value='$i'>$i</option>";
	}
	*/
   ?>
  </select> 
  <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Status Karyawan</td>
  <td>: 
  <select name="status_karyawan">
  	<?
	/*
		$sgetKa	= mssql_query("SELECT * FROM VStatusKaryawan WHERE kode='$row[stat_kar]'",$conn);
		$rgetKa = mssql_fetch_array($sgetKa);
		echo"<option value='$rgetKa[kode]'>$rgetKa[Nama]</option>";
	*/
	?>
  <option value="">--pilih--</option>
	<?
	/*
		$stat = mssql_query("SELECT * FROM VStatusKaryawan",$conn);
		while($rstat = mssql_fetch_array($stat)){
			echo"<option value='$rstat[kode]'>$rstat[Nama]</option>";
		}
		*/
	?>
  </select> <span class="required">*</span></td>
 </tr>
 </table>
 </fieldset>
 </td>
 -->
 </tr>
 <tr>
  <td align="right" colspan="2"><br /><br />
<input type="hidden" name="cat" value="penugasan" />
<input type="hidden" name="no" value="<?=$row[No]?>" />
<input type="reset" value="Batal" class="button" onClick="Javascript:history.back();" /><input type="button" value="<?=$Vbutton?>" class="button" onClick="Javascript:Validate();" />
  <br /><br />
  </td>
 </tr>
</table>
</form>
</td>
</tr>
<tr>
 <td colspan="2" style="border:none;"><? include("../footer.php"); ?></td>
</tr>
</table>
<script type="text/javascript">

var f = document.forms[0];
//MaskInput(f.nik,"9999999999");
MaskInput(f.tgl_surat,"99/99/9999");
MaskInput(f.tgl_dari,"99/99/9999");
MaskInput(f.tgl_sampai,"99/99/9999");
//MaskInput(f.gaji,"Rp. 9.999.999.999");
//MaskInput(f.tunjangan,"Rp. 9.999.999.999");
//]]>
</script>
<script type="text/javascript">
// script untuk popup calendar
	var calA = new calendar1(document.forms['FEmployee'].elements['tgl_surat']);
	calA.year_scroll = true;
	calA.time_comp = false;
	
	var calB = new calendar1(document.forms['FEmployee'].elements['tgl_dari']);
	calB.year_scroll = true;
	calB.time_comp = false;

	var calC = new calendar1(document.forms['FEmployee'].elements['tgl_sampai']);
	calC.year_scroll = true;
	calC.time_comp = false;
	
</script>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>
